/* List clicked View */
function getBasicInfo(id){
	var url = "getPolicyInfo.jsp";
	var param = {
		work_no : id
	};
	callAjax(url,param, "BASIC_VIEW");
}

/* Log List clicked Popup View */
function policy_detail(id){
	var url = "detail.jsp";
	var param = {
		ip_addr : id
	};
	openModal(url, param, 416, 408);
}

/* callAjax successAjax */
function successAjax(data, serviceName){
	if(serviceName == "BASIC_VIEW"){
		/* Info value setting */
		$('#system_name').val(data.rows[0].system_name);
		$('#policy_type').val(data.rows[0].policy_type);
		$('#control_root_login').val(data.rows[0].control_root_login);
		$('#account_lock').val(data.rows[0].account_lock);
		$('#suspend').val(data.rows[0].suspend);
		$('#notuse_account_lock').val(data.rows[0].notuse_account_lock);
		$('#control_dual_connect').val(data.rows[0].control_dual_connect);
		$('#pw_min_length').val(data.rows[0].pw_min_length);
		$('#pw_max_length').val(data.rows[0].pw_max_length);
		$('#compare_before_pw').val(data.rows[0].compare_before_pw);
		$('#compare_id_pw').val(data.rows[0].compare_id_pw);
		$('#used_pw_mix_rule').val(data.rows[0].used_pw_mix_rule);
		$('#compare_pw_same_str').val(data.rows[0].compare_pw_same_str);
		$('#compare_pw_straight_str').val(data.rows[0].compare_pw_straight_str);
		$('#compare_word').val(data.rows[0].compare_word);
		$('#control_before_pw').val(data.rows[0].control_before_pw);
		$('#last_sync_date').val(data.rows[0].last_sync_date);
	}
}

/* JqGrid Basic List */
function initGridBasic() {
	$("#gridList").jqGrid({
		url:'getJqgridPolicyList.jsp',
		mtype: 'post',
		//postData: {  },
		datatype: "json",
		colNames:['구분','시스템명','그룹명','상태','등록일자'],
		colModel:[
				{name:'type',index:'type', width:50,align:"right"},
				{name:'system_name',index:'system_name', width:80,align:"left",key:true},
				{name:'group_name',index:'group_name', width:180,align:"left"},
				{name:"status",index:'status', width:100,align:"right"},
				{name:'join_date',index:'join_date', width:50,align:"right"}
			],
		//loadonce:true,
		rowList: [0,5,10,15,20],
		rowNum:5,
		height:240,
		autowidth : true,
		sortname: "system_name",
		sortorder: 'DESC',
		viewrecords: true,
		multiselect: true,//앞에 체크박스처리
		multikey: "",//multikey: "ctrlKey/shiftKey",
		pager: '#pager_id',
		//editurl: "server.json",
      
		onSelectRow: function(id){  //row가 선택되었을 경우
			getBasicInfo(id);
		},
		loadComplete : function(data){
			pagecount = data.total;
			$("#pager").pager({ pagenumber: data.page, pagecount: pagecount, buttonClickCallback: PageClick });
        },
		loadError : function(xhr,st,err) {
			//jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
		},
		emptyrecords: "데이터가 존재하지 않습니다.",
		caption:'테이블',
		jsonReader: {
			repeatitems:false
		}
	});
	$("#gridList").jqGrid('navGrid','#pager_id',{edit:false,add:false,del:false,search:true});
}

/* JqGrid BasicLog List */
function initGridBasicLog() {
	$("#gridList2").jqGrid({
		url:'getJqgridPolicyLogList.jsp',
		mtype: 'post',
		//postData: {  },
		datatype: "json",
		colNames:['기간','구분','작업','결과','중요도','작업자','원격지'],
		colModel:[
				{name:'calender',index:'calender', width:50,align:"right",key:true},
				{name:'type',index:'type', width:80,align:"left"},
				{name:'work',index:'work', width:180,align:"left"},
				{name:"result",index:'result', width:100,align:"right"},
				{name:'important',index:'important', width:50,align:"right"},
				{name:'worker',index:'worker', width:50,align:"right"},
				{name:'ip_addr',index:'ip_addr', width:50,align:"right"}
			],
		rowList: [0,5,10,15,20],
		rowNum:5,
		height:130,
		autowidth : true,
		sortname: "calender",
		sortorder: 'DESC',
		viewrecords: true,
		multiselect: false,//앞에 체크박스처리
		multikey: "",//multikey: "ctrlKey/shiftKey",
		pager: '#pager_id',
		//editurl: "server.json",
      
		onSelectRow: function(id){  //row가 선택되었을 경우
			var rowData = jQuery(this).getRowData(id); 
            var ip_addr= rowData['ip_addr'];//replace name with you column
            policy_detail(ip_addr);
		},
		loadComplete : function(data){
			pagecount2 = data.total;
			$("#pager2").pager({ pagenumber: data.page, pagecount: pagecount2, buttonClickCallback: PageClick2 });
        },
		loadError : function(xhr,st,err) {
			//jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
		},
		emptyrecords: "데이터가 존재하지 않습니다.",
		caption:'테이블',
		jsonReader: {
			repeatitems:false
		}
	});
	$("#gridList2").jqGrid('navGrid','#pager_id',{edit:false,add:false,del:false,search:true});
}

var pagecount;
var pagecount2;

$(document).ready(function(){
	initGridBasic();
	initGridBasicLog();
	loadPolicySubPage("basic");
	initButton();
});
PageClick = function(pageclickednumber) {
    $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pagecount, buttonClickCallback: PageClick });
    $("#gridList").setGridParam({ postData: { pagePlug: pageclickednumber} }).trigger("reloadGrid");  // Postdata을 넘겨주고 url로 지정된 ajax 호출하고 Grid을 Relo
}
PageClick2 = function(pageclickednumber) {
    $("#pager2").pager({ pagenumber: pageclickednumber, pagecount: pagecount2, buttonClickCallback: PageClick2 });
    $("#gridList2").setGridParam({ postData: { pagePlug: pageclickednumber} }).trigger("reloadGrid");  // Postdata을 넘겨주고 url로 지정된 ajax 호출하고 Grid을 Relo
}

function initButton() {
	$("#btn_save").on("click",function(event) {
		var msg = confirm("저장하시겠습니까?");
		if( msg ) {
			
		}
	});
	$("#btn_del").on("click",function(event) {
		var msg = confirm("삭제하시겠습니까?");
		if( msg ) {
			
		}
	});
}